<?php


require "database.php";

$___f___=file_get_contents("sql.json");
$___f___=json_decode($___f___,1);
$offset=$_GET["offset"];
$limit=$_GET["limit"];
$offsetend=$offset+$limit;
$datas["total"]=count($___f___);
$p=0;
for ($i = 0; $i < count($___f___); $i++) {
    if($i+1>$offset && $i+1<$offsetend){
        $data[$p]["id"]                 =$___f___[$i]["id"];
        $data[$p]["category_title"]     =$___f___[$i]["order_on"];
        $data[$p]["username"]           =$___f___[$i]["money"];
        $data[$p]["title"]              =$___f___[$i]["project"];
        $data[$p]["subtitle"]           =$___f___[$i]["winning"];
        $data[$p]["thumb"]              =$___f___[$i]["deficit"];
        $data[$p]["diyname"]            =$___f___[$i]["periods"];
        if($___f___[$i]["result"]){
            $data[$p]["result"]             =$___f___[$i]["result"];
        }else{
            $data[$p]["result"]="未开奖";
        }
        $data[$p]["views"]              =$___f___[$i]["count"];
        $data[$p]["dislikes"]           =$___f___[$i]["total"];
        $p++;
    }
    if(!$offset){
        if($i<$limit){
            $data[$i]["id"]                 =$___f___[$i]["id"];
            $data[$i]["category_title"]     =$___f___[$i]["order_on"];
            $data[$i]["username"]           =$___f___[$i]["money"];
            $data[$i]["title"]              =$___f___[$i]["project"];
            $data[$i]["subtitle"]           =$___f___[$i]["winning"];
            $data[$i]["thumb"]              =$___f___[$i]["deficit"];
            $data[$i]["diyname"]            =$___f___[$i]["periods"];
            if($___f___[$i]["result"]){
                $data[$i]["result"]             =$___f___[$i]["result"];
            }else{
                $data[$i]["result"]="未开奖";
            }
            $data[$i]["views"]              =$___f___[$i]["count"];
            $data[$i]["dislikes"]           =$___f___[$i]["total"];
        }
        
    }
}
$datas["rows"]=$data;
return json($datas);
